const { defineConfig } = require("@vue/cli-service");

// console.log(process.env)
let baseURL = process.env.VUE_APP_BASEURL//获取环境中的服务器地址
//当前的环境是
console.log("当前的环境是:", process.env.VUE_APP_ENV)

let env = process.env.NODE_ENV;
//别名配置的方法
const path = require("path");
function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = defineConfig({
  publicPath: ".",//资源目录不去根目录拿,从相对路径拿
  transpileDependencies: true,
  lintOnSave: false,
  outputDir: env === "test" ? "testDir" : "dist",//构建之后文件输出的文件夹的名字
  //配置代理
  devServer: {
    proxy: {
      "/api": {
        target: baseURL,
        pathRewrite: {
          "^/api": ""
        }
      }
    }
  },
  //配置别名:引入文件的路径都可以简写
  chainWebpack: (config) => { //配置别名,合并webpack配置
    config.resolve.alias
      .set('%', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
      .set('static', resolve('src/static'))
  }
});
